package com.judian.smart.socket;

import android.util.Log;

import com.judian.smart.base.MyApplication;
import com.judian.smart.model.ConnectInfo;
import com.judian.smart.model.ForWardInfo;
import com.judian.smart.model.LoginInfo;
import com.judian.smart.model.ResponseInfo;
import com.judian.smart.util.AppTools;
import com.judian.smart.util.Base64;
import com.judian.smart.util.JSONHelper;
import com.judian.smart.util.SystemInfo;


public class ISocketCode {

    public static String setLogin(String masterName, String passWord, String masterOperator, String operatorPwd, int masterType) {
        LoginInfo info = new LoginInfo();
        info.setMasterID(getMasterID());
        info.setMasterName(masterName);
        info.setWiFi(SystemInfo.getSSID(MyApplication.getInstance()));
        info.setToID("000");
        info.setMsgType("Login");
        info.setContent("user Login");
        info.setPassWord(passWord);
        info.setMasterOp(masterOperator);
        info.setOpPwd(operatorPwd);
        info.setMasterType(1);
        String json = JSONHelper.toJSON(info);
        //return Base64.encode(json.getBytes());
        return json;
    }

    public static String setLine(String masterName, String passWord,
                                 String masterOperator, String operatorPwd, int masterType) {
        LoginInfo info = new LoginInfo();
        info.setMasterID(getMasterID());
        info.setMasterName(masterName);
        info.setWiFi(SystemInfo.getSSID(MyApplication.getInstance()));
        info.setToID("0000000000");
        info.setMsgType("Line");
        info.setContent("user Login");
        info.setPassWord(passWord);
        info.setMasterOp(masterOperator);
        info.setOpPwd(operatorPwd);
        info.setMasterType(masterType);
        String json = JSONHelper.toJSON(info);
        //return Base64.encode(json.getBytes());
        return json;
    }


    public static String setDownInfo(String content, String toID) {
        return getResponse("DownInfo", toID, content);
    }

    public static String setMasterfo(String content, String toID) {
        return getResponse("GetMasterInfo", toID, content);
    }

    public static String setDownApk(String content, String toID) {
        return getResponse("ApkInfo", toID, content);
    }

    public static String setForward(String content, String toID) {
        return getForWardString("Forward", content, toID);
    }

    public static String setResponse(String content, String toID) {
        return getResponse("Response", toID, content);
    }

    public static String setDeviceInfo(String content, String toID) {
        return getResponse("GetDeviceInfo", toID, content);
    }

    public static String setVoiceInfo(String content, String toID) {
        return getResponse("GetVoiceInfo", toID, content);
    }

    public static String setModeInfo(String content, String toID) {
        return getResponse("GetModeInfo", toID, content);
    }

    public static String setModeListInfo(String content, String toID) {
        return getResponse("GetModeList", toID, content);
    }

    public static String setAnHongInfo(String content, String toID) {
        return getResponse("GetAnHongInfo", toID, content);
    }

    public static String setCloudResponse(String content, String toID) {
        return getResponse("CloudResponse", toID, content);
    }

    public static String setGateWayInfo(String content, String toID) {
        return getResponse("GateWayInfo", toID, content);
    }

    public static String setSubscribeInfo(String content, String toID) {
        return getResponse("GetSubscribeInfo", toID, content);
    }

    public static String setPush(String content, String toID) {
        return getResponse("SetPush", toID, content);
    }

    public static String getError() {
        return "Error|00000|0000|0|00000|DST";
    }

    public static String getResponse(String msgType, String toID, String content) {
        ResponseInfo info = new ResponseInfo();
        info.setMasterID(getMasterID());
        info.setToID(toID);
        info.setMsgType(msgType);
        info.setContent(content);
        info.setMsgState(0);
        info.setMasterType(0);
        String json = JSONHelper.toJSON(info);
        //return Base64.encode(json.getBytes());
        return json;
    }

    private static String masterID = "";

    public static String getMasterID() {
        if (masterID.equals("")) {
            masterID = SystemInfo.getMasterID(MyApplication.getInstance());
        }
        return masterID;
    }

    public static String getForWardString(String msgType, String content, String toID) {
        ForWardInfo info = new ForWardInfo();
        info.setMsgType(msgType);
        info.setMasterID(getMasterID());
        info.setToID(toID);
        info.setMasterType(0);
        info.setContent(content);
        info.setCreateTime(AppTools.getCurrentTime());
        String json = JSONHelper.toJSON(info);
        Log.e("json", json);
        //return Base64.encode(json.getBytes());
        return json;
    }


    public static String setConnect(String toID, String userName, String passWord, int masterType) {
        ConnectInfo info = new ConnectInfo();
        info.setMasterID(getMasterID());
        info.setToID(toID);
        info.setMsgType("Connect");
        info.setMasterType(masterType);
        info.setPassWord(passWord);
        info.setUserName(userName);
        info.setContent("content");
        info.setCreateTime(AppTools.getCurrentTime());
        String json = JSONHelper.toJSON(info);
        //return Base64.encode(json.getBytes());
        return json;
    }

    public static String getForWardString(String msgType, String content, String toID, int masterType) {
        ForWardInfo info = new ForWardInfo();
        info.setMsgType(msgType);
        info.setMasterID(getMasterID());
        info.setToID(toID);
        info.setMasterType(masterType);
        info.setContent(content);
        info.setCreateTime(AppTools.getCurrentTime());
        String json = JSONHelper.toJSON(info);
        Log.e("json", json);
        //return Base64.encode(json.getBytes());
        return json;
    }

    public static String setForwardOut() {
        return getForWardString("ForwardOut", "user out", "000", 1);
    }
}
